package com.zj.dmsproxy.utils;

import com.zj.dmsproxy.annotation.DmsScan;
import com.zj.dmsproxy.model.DmsInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.AnnotatedElementUtils;

import java.util.Objects;

/**
 * @author arthur_zhou
 * @date 2023/10/18 12:24
 */
@Slf4j
public class DmsUtil {

    /**
     * 读取配置文件获取dms路径
     *
     * @param clazz 代理类class
     * @return dms信息
     */
    public static DmsInfo getDmsInfo(Class<?> clazz) {
        DmsInfo dmsInfo = new DmsInfo();
        DmsScan scan = AnnotatedElementUtils.getMergedAnnotation(clazz, DmsScan.class);
        if (Objects.isNull(scan)) {
            log.warn("{}的@DmsScan注解找不到", clazz.getName());
            return dmsInfo;
        }
        dmsInfo.setInfoName(scan.infoName());
        return dmsInfo;
    }

}
